package cn.maihe.elg.operation.model.enums;

import java.util.Arrays;

/**
 * @author JHWei on 2018-07-12.
 * @ 创建日期：2018-07-12
 * 0-禁用,1-启用
 */
public enum InvoiceFlagEnum {

    /**
     * 禁用
     *
     */
    INVOICEPRE(0,"待开票"),
    INVOICEAPPLY(2,"申请开票中"),

    /**
     * 启用
     *
     */
    INVOICED(1,"已开票");

    private int value;
    private String label;

    InvoiceFlagEnum(int value, String label) {
        this.value = value;
        this.label = label;
    }

    public int getValue() {
        return value;
    }

    public String getLabel() {
        return label;
    }

    public static boolean contains(int value){
        for(InvoiceFlagEnum typeEnum : InvoiceFlagEnum.values()){
            if(typeEnum.value==value){
                return true;
            }
        }
        return false;
    }

    public static InvoiceFlagEnum resolve(int value) {
        return Arrays.stream(values()).filter(o -> o.getValue() == value).findFirst().orElseThrow(() -> new RuntimeException("开票状态非法[" + value + "]"));
    }
    public static InvoiceFlagEnum resolve(String valueStr) {
        try {
            return resolve(Integer.valueOf(valueStr));
        } catch (NumberFormatException e) {
            throw new RuntimeException("开票状态非法[" + valueStr + "]", e);
        }
    }

    public static String getDescByFlag(int flag) {
        try {
            InvoiceFlagEnum typeEnum = resolve(flag);
            return typeEnum.getLabel();
        } catch (Exception e) {
        }
        return "";
    }

}
